package ding.com.multifragment;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import ding.com.multifragment.struct.FuntionNoParamNoResult;
import ding.com.multifragment.struct.FuntionWithParamAndResult;
import ding.com.multifragment.struct.FuntionWithParamNoResult;
import ding.com.multifragment.struct.FuntionWithResultOnly;
import ding.com.multifragment.struct.FuntionsManager;

public class MainActivity extends AppCompatActivity {

    private   BlankFragment detection;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         detection=new BlankFragment();
        FragmentManager fm=getSupportFragmentManager();
        FragmentTransaction transaction
                =fm.beginTransaction();
        transaction.replace(R.id.fl,detection);
        transaction.commit();
    }


    public void setFuntionsManager(BaseFragment fragment){
//        FragmentManager fm=getSupportFragmentManager();
//        BaseFragment fragment= (BaseFragment) fm.findFragmentByTag(tag);
        FuntionsManager funtionsManager=FuntionsManager.getInstance();
        fragment.setFuntionsManager(funtionsManager.addFuntion(new FuntionNoParamNoResult("无参无返回") {
            @Override
            public void function() {
                Toast.makeText(MainActivity.this,"无参无返回",Toast.LENGTH_SHORT).show();
            }
        }).addFuntion(new FuntionWithParamNoResult("有参无返回") {
            @Override
            public void function(Object o) {
                Toast.makeText(MainActivity.this,"有参无返回",Toast.LENGTH_SHORT).show();
            }
        }).addFuntion(new FuntionWithResultOnly<String>("无参有返回") {
            @Override
            public String function() {
                return "无参有返回";
            }
        }).addFuntion(new FuntionWithParamAndResult<String,String>("有参有返回") {
            @Override
            public String function(String data) {
                return "有参有返回";
            }
        }));
    }
}
